<template lang="pug">
  el-dialog(
    :visible="visibleDialog"
    :title="title"
    width="840px"
    append-to-body
    destroy-on-close
    v-el-drag-dialog
    @close="$_handleCancel"
  )
    s-table(
      ref="table"
      :queryFn="tableObj.queryFn"
      :column="tableObj.column"
      :queryPropsParams="{ childrenId: id }"
    )
      template(slot="action" slot-scope="text, scope, index")
        el-button(size="mini" @click="infoRoute(scope.healthBaseInfoId, index)" effect="plain" icon="el-icon-document el-icon--right") 查看
</template>
<script>
import elDragDialog from '@/directive/el-drag-dialog'
import { getChildrenHealthPageByChildrenId } from '../../detail/api'
import { column } from './config'

export default {
  directives: { elDragDialog },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    id: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      tableObj: {
        column,
        queryFn: getChildrenHealthPageByChildrenId
      }
    }
  },
  computed: {
    visibleDialog: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    // 详情跳转
    infoRoute (id, index) {
      const list = this.$refs.table.localTableData
      console.log(list)
      this.$router.push({
        path: '/childCare/evaluation/childrenHealth/info',
        query: {
          id,
          beforeId: list[index + 1]?.healthBaseInfoId
        }
      })
    },
    $_handleCancel () {
      this.visibleDialog = false
    }
  }
}
</script>
